﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class BasicBase_Duty_DutyList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DptStation.SelectedIndexChanged += new EventHandler(Changed);
        if (!IsPostBack)
            Bind();
    }
    private void Bind()
    {
        //判断当前用所在组
        string Dept = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        if (Dept == null || Dept.Length < 5)
            return;

        string strSql = "";
        if (Dept.Substring(4, 1).Equals("0"))
            strSql += "  Left(DepartmentID,5)='" + Dept.Substring(0, 5) + "'";
        else
            strSql += "  DepartmentID='" + Dept + "'";

        DptStation.DataSource = Yipusoft.Duty.BLL.DutyType.GetList(strSql);
        DptStation.DataTextField = "DTName";
        DptStation.DataValueField = "DutyType";
        DptStation.DataBind();
        Changed(DptStation, new EventArgs());
    }
    protected string GetDepartmentName(string DepartmentID)
    {
        try
        {
            DepartmentID= Yipusoft.Account.BLL.Department.GetDepartment(DepartmentID).FullName;
        }
        catch { };
        return DepartmentID;
    }
    protected void Changed(object sender, EventArgs e)
    {
        string Dept = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        string strSql = "";

        if (Dept.Substring(4, 1).Equals("0"))
            strSql += "  Left(DepartmentID,5)='" + Dept.Substring(0, 5) + "'";
        else
            strSql += "  DepartmentID='" + Dept + "'";

        DropDownList Dpt = sender as DropDownList;
        GvwList.DataSource = Yipusoft.Duty.BLL.Member.GetList(" UserID in(Select UserID From MemberStation Where " + strSql + " And DutyType='" + Dpt.SelectedValue+ "')");
        GvwList.DataBind();

    }


    protected void BtnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddMember.aspx?DutyType="+this.DptStation.SelectedValue);
    }
    protected void GvwList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblID = e.Row.FindControl("lblID") as Label;
            lblID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
}
